﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyClock
{
    public partial class Form1 : Form
    {
        public delegate void Act(int[] a);
        public delegate void Ac();
        public event Act tic;
        public event Ac ala;
        Act tick = new Act(Clock.tick);
        Ac alarm= new Ac(Clock.alarm);

        public Form1()
        {
            InitializeComponent();
        }

    

        private void button1_Click(object sender, EventArgs e)
        {   
            string h=textBox1.Text, m=textBox2.Text,s=textBox3.Text;
            int ho, mi, se;
    
            bool hValid = int.TryParse(h, out ho) && (ho >= 0);
            bool mValid = int.TryParse(m, out mi) && (mi >= 0) && (mi <= 59);
            bool sValid = int.TryParse(s, out se) && (se >= 0) && (se <= 59);
            //判断输入是否合法
            if (hValid&&mValid&&sValid)
            {   int[] times = {ho, mi, se};
                Clock.ifAlarm = false;
                Clock.ifTick = true;
                label5.Text = "计时开始！";

           //     for (; ; )
                {
                    tick(times);
                    label6.Text = ho + ":" + mi + ":" + se;
                    Thread.Sleep(1000);

                    if (Clock.ifAlarm == true)
                        break;
                }
                    alarm();
                    
                
            }
            else
            {
                label5.Text = "不合法的输入请重新输入";
            }

           
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //alarm();
            Clock.ifTick = !Clock.ifTick;
        }
    }
}
